#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
int n,m,k,T;

signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin >> T;
	while(T--) {
		string x;
		cin >> x;
		int cnt = 0;
		int pre = 0;
		vector<char> ans;
		int n = x.size();
		x = x + "#";
		for(int i = 0; i < n; ++ i) {
			if(x[i] == ')') {
				if(cnt == 0) {
					int num = pre - cnt;
					while(num --) ans.push_back(')');
					pre = 0;
					ans.push_back(')');
				}else cnt --;
			}
			if(x[i] == '(') {
				if(pre != cnt) {
					int num = pre - cnt;
					while(num --) ans.push_back(')');
				}
				ans.push_back('(');
				cnt++;
				pre = cnt;
			}
		}
		if(cnt) cout << "impossible";
		else 
		for(auto j : ans) {
			cout << j;
		}
		cout << endl;
	}
	
	return 0;
}